package com.xio.cloud.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xio.cloud.domain.Storage;
import com.xio.cloud.mapper.StorageMapper;
import com.xio.cloud.service.StorageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @Author: xio
 * @Description: ${Description}
 * @Date: 2021/3/31 20:58
 */
@Slf4j
@Service
public class StorageServiceImpl
        extends ServiceImpl<StorageMapper, Storage>
        implements StorageService{

    @Override
    public boolean decrease(Long productId, Integer count) {
        log.info("- - - - - > seata-storage-service: 减少库存开始");
        // 查找产品库存
        Storage storage = lambdaQuery()
                .eq(Storage::getProductId, productId).one();

        // 更新库存
        storage.setUsed(storage.getUsed() + count);
        storage.setResidue(storage.getResidue() - count);
        boolean result = updateById(storage);
        log.info("- - - - - > seata-storage-service: 减少库存结束");
        return result;
    }
}
